package com.hzcx.app.simplechat.ui.chat.presenter;

import android.content.Context;

import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.base.BasePresenter;
import com.hzcx.app.simplechat.model.ChatModel;
import com.hzcx.app.simplechat.ui.chat.bean.ChatQuickMsgBean;
import com.hzcx.app.simplechat.ui.chat.contract.ChatQuickMsgAddContract;
import com.hzcx.app.simplechat.ui.chat.contract.ChatQuickMsgManagerContract;

import java.util.List;

public class ChatQuickMsgManagerPresenter extends BasePresenter<ChatQuickMsgManagerContract.View> implements ChatQuickMsgManagerContract.Presenter {

    /**
     *  获取快捷回复列表
     * @param context
     */
    @Override
    public void getQuickMsgList(Context context) {
        ChatModel.getChatQuickMsgList(context, new BaseDialogObserver<List<ChatQuickMsgBean>>(context) {
            @Override
            protected void onSuccess(List<ChatQuickMsgBean> data) {
                mView.quickMsgResult(data);
            }
        });
    }

    /**
     *  删除快捷回复
     * @param context
     * @param reply_id
     * @param pos
     */
    @Override
    public void deleteChatQuickMsg(Context context, int reply_id, int pos) {
        ChatModel.deleteChatQuickMsg(context, reply_id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.deleteSuccess(pos);
            }
        });
    }

    /**
     *  快捷回复排序
     * @param context
     * @param data
     */
    @Override
    public void moveChatQuickMsg(Context context, List<ChatQuickMsgBean> data) {
        String id = "";
        for (int i = 0; i < data.size(); i++) {
            if (i == data.size() - 1) {
                id = id + data.get(i).getReply_id();
            } else {
                id = id + data.get(i).getReply_id() + ",";
            }
        }
        ChatModel.moveChatQuickMsg(context, id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.moveSuccess();
            }
        });
    }
}
